﻿@using ZR.CodeGenerator
@model ZR.CodeGenerator.Model.GenerateDto;
@{
	var genTable = Model.GenTable;
	var subTableOptions = Model.SubTableOptions;
	var options = Model.GenOptions;
	var replaceDto = Model.ReplaceDto;
	var parentId = genTable?.Options?.ParentMenuId ?? 0;
}
use ZrAdmin;

-- @(genTable.FunctionName)菜单
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time) 
VALUES ('@(genTable.FunctionName)', @(parentId), 999, '@(genTable.BusinessName)', '@(CodeGeneratorTool.FirstLowerCase(genTable.ModuleName))/@(genTable.BusinessName)', 0, 0, 'C', '0', '0', '@(replaceDto.PermissionPrefix):list', 'icon1', 'system', null);

-- 按钮父菜单id
DO $$
	DECLARE @@menuId integer;
	DECLARE @@nowTime datetime;
BEGIN
	SELECT @@@@identity INTO @@menuId;
	SELECT now()::timestamp(0)without time zone INTO @@nowTime

	INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
	VALUES ('查询', @@menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '@(replaceDto.PermissionPrefix):query', '', 'system', @@nowTime);

	INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
	VALUES ('新增', @@menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '@(replaceDto.PermissionPrefix):add', '', 'system', @@nowTime);

	INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
	VALUES ('删除', @@menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '@(replaceDto.PermissionPrefix):delete', '', 'system', @@nowTime);

	INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
	VALUES ('修改', @@menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '@(replaceDto.PermissionPrefix):edit', '', 'system', @@nowTime);
	   
   	INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time) 
   	VALUES ('导出', @@menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '@(replaceDto.PermissionPrefix):export', '', 'system', @@nowTime);

END $$;

SELECT * FROM sys_menu WHERE parentId = @@menuId;
SELECT * FROM sys_menu WHERE menuId = @@menuId;
